package cn.jiedh.app.meiweidk.Utils.event;

/**
 * @name： 单例类
 * @author： 杨 广
 * @phone： 17382373271
 * @createTime： 2017/3/27
 * @modifyTime： 2017/3/27
 * @explain：
 */

public class EventUtils {
    private static EventUtils instance;
    private ConcreteObservables observableA;

    public static EventUtils getDefault() {
        if (instance == null) {
            synchronized (EventUtils.class) {
                if (instance == null) {
                    instance = new EventUtils();
                }
            }
        }
        return instance;
    }

    private EventUtils() {
        observableA = new ConcreteObservables();
    }

    /**
     * register a observer
     * @param observer
     */
    public void register(Observers observer) {
        observableA.addObserver(observer);
    }

    /**
     * unregister a observer
     * @param observer
     */
    public void unregister(Observers observer) {
        observableA.removeObserver(observer);
    }

    /**
     * post a objict message to all observer
     * @param obj
     */
    public void forward(Object obj) {
        observableA.notifyObservers(obj);
    }
}
